﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebAPILib.APIs.DaZhouDianPing;
using DBLayer;


namespace MyWebDataSpider
{
    public class ProcessBO
    {
        static WebAPILib.APIs.DaZhouDianPing.DianPingAPIs WebAPI = new WebAPILib.APIs.DaZhouDianPing.DianPingAPIs();
        
        internal ShopInfo_Result GetShopInfosByWebAPI(ShopInfo_QueryParams queryParams)
        {
            return WebAPI.GetShopInfosByWebAPI(queryParams);
        }

        public bool InsertShopInfo(ShopInfo shopInfo)
        {
            try
            {

                //string InsertSql=string.Format(
                //    "Insert into shopsinfo (business_id,name,branch_name) values({0},'{1}','{2}')"
                //    ,shopInfo.business_id.ToString()
                //    ,shopInfo.name
                //    ,shopInfo.branch_name
                //    );




                DB.Execute(BatchInsertTest());

                //DB.ExecuteTransaction(TranscationInsertTest(), null);
                return true;
            }
            catch (Exception ex)
            {

                throw ex;
            }
 
        }

        private string BatchInsertTest()
        {
            string TestInsert = "Insert into shopsinfo (business_id,name,branch_name) values (0,'A','B')";
            
            StringBuilder sb = new StringBuilder();
            
            sb.Append(TestInsert);

            for (int i = 0; i < 100000; i++)
            {
                sb.AppendFormat(",({0},'{1}','{2}')" , i.ToString(),"A" , "B");
            }

            return sb.ToString();
        }

        private List<string> TranscationInsertTest()
        {
            string TestInsert1 = "Insert into shopsinfo (business_id,name,branch_name) values (0,'A','B')";
            string TestInsert2 = "Insert into deals (dealsId,description,url,branchId) values ('A','B','c',@@IDENTITY)";


            List<string> list1 = new List<string>();

            list1.Add(TestInsert1);
            list1.Add(TestInsert2);

            return list1;
        }

    }
}
